
const axios = require("axios")
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const fs = require("fs")
const path = require("path")

// const rs6 = require("./rs6")
// const ts = require("./ts")


login()

async function login(user, pass) {
    let rs6Secret;
    let cookie;
    try {
        const result = await axios.get("https://pcticket.cstm.org.cn/", {
            "headers": {
                "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
                "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
                "cache-control": "no-cache",
                "pragma": "no-cache",
                "priority": "u=0, i",
                "sec-ch-ua": "\"Chromium\";v=\"134\", \"Not:A-Brand\";v=\"24\", \"Microsoft Edge\";v=\"134\"",
                "sec-ch-ua-mobile": "?0",
                "sec-ch-ua-platform": "\"Windows\"",
                "sec-fetch-dest": "document",
                "sec-fetch-mode": "navigate",
                "sec-fetch-site": "same-origin",
                "sec-fetch-user": "?1",
                "upgrade-insecure-requests": "1"
            },
            "referrer": "https://pcticket.cstm.org.cn/personal/notice_detail?id=62",
            "referrerPolicy": "strict-origin-when-cross-origin",
            "body": null,
            "method": "GET",
            "mode": "cors",
            "credentials": "omit"
        })
    } catch (error) {
        // console.log(error.response.status);
        cookie = error.response.headers["set-cookie"][0].split(";")[0]
        rs6Secret = error.response.data


    }
    fs.writeFileSync(path.join(__dirname, "index.html"), rs6Secret, 'utf8');
    const dom = new JSDOM(rs6Secret);
    const src = dom.window.document.querySelectorAll("script")[1].src
    const ts = dom.window.document.querySelectorAll("script")[0].innerHTML

    fs.writeFileSync(path.join(__dirname, "ts.js"), ts, 'utf8');
    let js;
    try {
        const result = await axios.get(`https://pcticket.cstm.org.cn${src}`, {
            "headers": {
                "accept": "*/*",
                "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
                "cache-control": "no-cache",
                "pragma": "no-cache",
                "priority": "u=1",
                "sec-ch-ua": "\"Chromium\";v=\"134\", \"Not:A-Brand\";v=\"24\", \"Microsoft Edge\";v=\"134\"",
                "sec-ch-ua-mobile": "?0",
                "sec-ch-ua-platform": "\"Windows\"",
                "sec-fetch-dest": "script",
                "sec-fetch-mode": "no-cors",
                "sec-fetch-site": "same-origin",
                "cookie": cookie,
                "Referer": "https://pcticket.cstm.org.cn/",
                "Referrer-Policy": "strict-origin-when-cross-origin"
            },
            "body": null,
            "method": "GET"
        }
        )
        js = result.data

    } catch (error) {

    }

    fs.writeFileSync(path.join(__dirname, "rs6.js"), js, 'utf8');



}




